#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

### ###########################################################
## Get frame with depth
#


def frame(depth=-1):
    """Call stack frame.

    NOTE: the depth is based on caller
    """

    depth_all = 1
    while True:
        try:
            sys._getframe(depth_all)
            depth_all += 1
        except:
            break

    if depth >= depth_all - 1:
        depth = -1
    else:
        depth += 1

    pos = (depth_all + depth) % depth_all
    return sys._getframe(pos)
